import 'package:boss/provider/commodity_provider.dart';
import 'package:boss/ui/page/costManagement/page/cost_management_batch_page.dart';
import 'package:boss/ui/page/costManagement/widget/cost_management_browser.dart';
import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:boss/ui/widget/label_button.dart';
import 'package:boss/ui/widget/loading/loading.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';
import 'package:provider/provider.dart';
import 'package:router/annotation.dart';

@RouterConfig(CostManagementPage.pageName)
class CostManagementPage extends StatefulWidget {
  static const pageName = '/costManagementPage';

  @override
  _CostManagementPageState createState() => _CostManagementPageState('成本管理');
}

class _CostManagementPageState extends BaseState<CostManagementPage> {
  _CostManagementPageState(String pageName) : super(pageName);

  var provider;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    Future.delayed(Duration(milliseconds: 0), () async {
      provider = Provider.of<CommodityProvider>(
        context,
        listen: false,
      );
      try {
        showLoadingToast();
        await provider?.initData();
      } catch (e) {} finally {
        hideLoadingToast();
      }
    });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CenterTitleAppBar(
        title: '成本管理',
        actions: <Widget>[
          LabelButton(
            title: '+批量设置',
            padding: EdgeInsets.only(left: 8, top: 2, bottom: 2),
            onTap: () {
              Navigator.pushNamed(context, CostManagementBatchPage.pageName);
            },
          ),
        ],
      ),
      body: CostManagementBrowser(),
    );
  }
}
